﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace AuditModel
{
    public class AnnualEventBL:IAnnualEventBL
    {

        #region IAnnualEventBL Members
        private AuditDBEntities db;
        public AnnualEventBL()
        {
            db = new AuditDBEntities();
        }
        public AnnualEvent GetAnnualEvent(string eventID)
        {
            //throw new NotImplementedException();
            var annualEvent = (from e in db.AnnualEvents
                     where e.ID.ToLower().Trim() == eventID.ToLower().Trim()
                     select e).Single();
            return annualEvent;
        }

        public IEnumerable<AnnualEvent> GetActiveEvents()
        {
            //throw new NotImplementedException();
            string status=AnnualEventStatus.Inactive.ToString();
            var events = (from e in db.AnnualEvents
                          where e.Status !=status
                          select e).ToList();
            return events;
        }

        #endregion

        #region IAnnualEventBL Members


        public void Update(AnnualEvent annualEvent)
        {
            db.AnnualEvents.Attach(annualEvent);
            db.ObjectStateManager.ChangeObjectState(annualEvent, EntityState.Modified);
            db.SaveChanges();
        }

        #endregion
    }
}
